package utils;

import java.util.Base64;

public class MyBase64 {

    public String encode1(String str) {
        String str1 = Base64.getEncoder().encodeToString(str.getBytes());
        System.out.println(str1);
        return str1;
    }

    public String encode2(String str) {
        String str2 = Base64.getUrlEncoder().encodeToString(str.getBytes());
        System.out.println(str2);
        return str2;
    }

    public void decoder1(String str) {
        byte[] str1 = Base64.getDecoder().decode(str.getBytes());
        System.out.println(new String(str1));
    }

    public void decoder2(String str) {
        byte[] str2 = Base64.getUrlDecoder().decode(str.getBytes());
        System.out.println(new String(str2));
    }

    public static void main(String[] args) {
        MyBase64 myBase64 = new MyBase64();

        String a = "123";
        String b = "http://www.baidu.com?a=b+c&d=g";

        String ae = myBase64.encode1(a);
        myBase64.decoder1(ae);

        String ae1 = myBase64.encode1(b);
        myBase64.decoder1(ae1);

        String be = myBase64.encode2(a);
        myBase64.decoder2(be);

        String be1 = myBase64.encode2(b);
        myBase64.decoder2(be1);
    }

}
